package me.baicai.weixin.provider.repository;

import com.alibaba.fastjson.JSONObject;
import me.baicai.weixin.entity.order.FaultRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FaultRecordRepository  extends JpaRepository<FaultRecord, Long> {

    @Query(value ="select f.id,f.created,f.images,f.message,f.sn,f.tel, o.amount , TIMESTAMPDIFF(MINUTE, o.created, f.created) as min ,s.shopName,s.address, d.remark from fault_record f LEFT JOIN `order` o on o.id = f.orderId LEFT JOIN shop s on s.id = f.shopId LEFT JOIN device d on d.sn = o.deviceSN   where f.`status` = ?2 and s.id = ?1", nativeQuery = true)
    List<JSONObject> findAllByShopIdAndStatus(Integer shopId, String status);

}
